//
//  FPBannerCell.m
//  FinanceProject
//
//  Created by 陈显摆 on 2025/1/21.
//

#import "FPBannerCell.h"
#import "FPHomeBannerModel.h"

@interface FPBannerCell () <SDCycleScrollViewDelegate>

@end

@implementation FPBannerCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.scrollView.clipsToBounds = YES;
    self.scrollView.layer.cornerRadius = 12.f;
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)analysisBannerSource:(NSArray *)source {
    
    [self.cycleScrollView adjustWhenControllerViewWillAppera];
    
    NSMutableArray *temp = NSMutableArray.array;
    
    for (FPHomeBannerModel *model in source) {
        
        [temp addObject:model.imageUrl];
    }
    if (temp.count == 0) {
        [temp addObject:IMG(@"bg_home_banner")];
    }
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0,  SCREEN_WIDTH - 32.f, self.scrollView.height) shouldInfiniteLoop:YES imageNamesGroup:temp];
    self.cycleScrollView.delegate = self;
    self.cycleScrollView.placeholderImage = IMG(@"bg_banner_placeholder");
    self.cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    [self.scrollView addSubview:self.cycleScrollView];
//    self.cycleScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
    if (temp.count > 1) {
        self.cycleScrollView.autoScrollTimeInterval = 3.0;//轮播时间间隔，默认1.0秒，可自定义
    }
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
   
    NSLog(@"%ld",(long)index);
    self.block(index);
}




@end
